package com.ningxia.water.controller.geographic;

import com.ningxia.water.entity.ZtAreaInfo;
import com.ningxia.water.reuslt.Result;
import com.ningxia.water.reuslt.ResultResponse;
import com.ningxia.water.service.IZtAreaInfoService;
import com.ningxia.water.utils.CommonUtils;
import com.ningxia.water.vo.out.ApplicantVo;
import com.ningxia.water.vo.out.ZonePidVo;
import com.ningxia.water.vo.out.ZoneVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huangzhen
 * @create 2021-05-14 21:04
 */
@RestController
@RequestMapping("/area")
@Api(tags = {"地理信息-5-工业园区API"})
public class AreaController {

    @Autowired
    private IZtAreaInfoService areaInfoService;

    @GetMapping("/getareainfo")
    @ApiOperation("获取全部工业园区地理信息")
    public Result getAreaInfo() {
        List<ZoneVo> list = areaInfoService.getAreaInfos();
        return ResultResponse.getSuccessResult(list);
    }

    @PostMapping("/insertareainfo")
    @ApiOperation(value = "新增工业园区")
    public Result insertAreaInfo(@RequestBody ZtAreaInfo areaInfo) {
        return CommonUtils.commonResult(areaInfoService.save(areaInfo));
    }

    @PutMapping("/updateareainfo")
    @ApiOperation(value = "根据ID更新工业园区")
    public Result updateAreaInfo(@RequestBody ZtAreaInfo areaInfo) {
        return CommonUtils.commonResult(areaInfoService.updateById(areaInfo));
    }


    @DeleteMapping("/deleteareainfo")
    @ApiOperation(value = "根据id删除工业园区")
    public Result deleteTownInfo(@RequestParam("areaId") Integer areaId) {
        return CommonUtils.commonResult(areaInfoService.removeById(areaId));
    }


    @GetMapping("/getallapplicants")
    @ApiOperation(value = "获取该工业园区下的所有用水户")
    public Result getAllApplicants(@RequestParam("areaId") Integer areaId) {
        List<ApplicantVo> list = areaInfoService.getAllApplicants(areaId);
        return ResultResponse.getSuccessResult(list);
    }


    @GetMapping("/getarearelationship")
    @ApiOperation(value = "获取工业园区及其对应的城市")
    public Result getAreaRelationship() {
        List<ZonePidVo> list = areaInfoService.getAreaRelationship();
        return ResultResponse.getSuccessResult(list);
    }

}
